import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'
// const path = require('path')

Vue.use(Vuex)

const files = require.context('./modules', false, /\.js$/)
const regex = /.*\/(.*)\.js$/;

const modules = {}
files.keys().forEach(key => {
  let moduleName = regex.exec(key);
  let name ='user'
  if(moduleName?.length > 1){
    name = moduleName[1]
  }
  // const name = path.basename(key, '.js')
  modules[name] = files(key).default || files(key)
})

export default new Vuex.Store({
  modules,
  
  getters
})
